package com.itheima.demo6executorService;

import java.util.concurrent.*;

public class ExecutorServiceDemo1
{
    public static void main(String[] args) {
        //创建一个线程池
        ExecutorService es = new ThreadPoolExecutor(3,5,10,
                TimeUnit.SECONDS,new ArrayBlockingQueue<>(5),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.DiscardOldestPolicy());
        MyRunnable r = new MyRunnable();
        //处理完之后不会销毁
        //处理Runnable接口对象
        es.execute( r);//自动启动
        es.execute( r);
        es.execute( r);
        //超过自己规定的主要线程 会复用
        es.execute( r);
        es.execute( r);
      //callable
        MyCallable c = new MyCallable(100);
        //处理callable接口对象
        Future<Integer> f = es.submit(c);
        //拿到结果
         try
             {
                 System.out.println(f.get());
             }
             catch (Exception e)
             {
                 e.printStackTrace();
             }
    }
}
